package com.pccw.ssh.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.pccw.ssh.factory.SpringBeanFactory;
import com.pccw.ssh.form.StockForm;
import com.pccw.ssh.service.StockService;
import com.pccw.ssh.vo.StockVO;

public class StockQueryAction extends Action {
	
	private Log log = LogFactory.getLog(this.getClass());

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		request.getSession(false).setAttribute("sessionParameterTest", "valueInSession");

		StockForm stockForm = (StockForm) form;
		StockVO stockVO = stockForm.toVO();
		StockService stockService = (StockService) SpringBeanFactory.getBean("stockService");
//		stockVO = stockService.getByPK(stockVO.getNum());
//		List<StockVO> stockVOs = stockService.getByAttribute("name",stockVO.getName());
		List<StockVO> stockVOs = stockService.getByVO(stockVO);
		stockVO = stockVOs.get(0);
		request.setAttribute("stockVO", stockVO);
		log.info("NUM:"+stockVO.getNum()+" Name:"+stockVO.getName()+" Price"+stockVO.getPrice());
		return mapping.findForward("success");

	}

}
